var realnameType;
$(function(){
	$.ajax({
		url:'../userController/getRealName',
		success:function(data){
			console.log(data)
			if(data!=null && data!=""){
				realnameType="0";
				$("#id").val(data.id);
				$("#id").attr("readonly","readonly");
				if(data.realName!=null && data.realName!=""){
					$("#realname").val(data.realName);
					$("#realname").attr("readonly","readonly");
				}
				if(data.idCard!=null && data.idCard!=""){
					$("#idCard").val(data.idCard);
					$("#idCard").attr("readonly","readonly");
				}
			}else{
				realnameType="1";
			}
		},
	})
})
$(function(){
	$.ajax({
		url:'../userController/getUser',
		success:function(data){
			$("#phone").val(data.phone);
			$("#phone").attr("readonly","readonly");
		}
	})
})

$(".button").click(function(){
	var phone = $("#phone").val();
	var realname = $("#realname").val();
	var id = $("#id").val();
	var idcard = $("#idCard").val();
	if(realname=="" || realname == null || realname=="undefined"){
		alert("请填写真实姓名");
	}else if(phone =="" || phone == null || phone =="undefined"){
		alert("请填写电话号");
	}else if(!/^1[0-9]{10}$/.test(phone)){
		alert("电话号格式不正确");
	}else if(idcard=="" || idcard == null || idcard=="undefined"){
		alert("请填写身份证号");
	}else if(!/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]/.test(idcard)){
		alert("身份证号格式不正确");
	}else{
		$.ajax({
			url:'../userController/extension',
			data:{
				"id":id,
				"phone":phone,
				"idcard":idcard,
				"realname":realname,
				"realnameType":realnameType
			},
			success:function(data){
				console.log(data)
				if(data){
					alert("提交成功");
					window.location.href="../html/Me.html"
				}
			}
		})
	}
})